package com.smartsystem.common.controller;

import com.smartsystem.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 首页控制器
 */
@RestController
@RequestMapping("/api")
@Tag(name = "首页接口", description = "系统首页相关接口")
public class IndexController {

    /**
     * 系统首页接口
     * @return 系统首页信息
     */
    @GetMapping
    @Operation(summary = "系统首页", description = "获取系统首页信息和导航")
    public Result<Map<String, Object>> index() {
        Map<String, Object> indexInfo = new HashMap<>();
        
        indexInfo.put("title", "智慧超市管理系统");
        indexInfo.put("version", "v1.0.0");
        indexInfo.put("description", "欢迎使用智慧超市管理系统API服务");
        indexInfo.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        
        // API导航信息
        Map<String, String> navigation = new HashMap<>();
        navigation.put("apiDoc", "/doc.html");
        navigation.put("druidMonitor", "/druid/index.html (用户名: admin, 密码: admin123)");
        navigation.put("healthCheck", "/api/test/health");
        navigation.put("systemInfo", "/api/test/info");
        navigation.put("welcome", "/api/test/welcome");
        indexInfo.put("navigation", navigation);
        
        // 模块信息
        Map<String, String> modules = new HashMap<>();
        modules.put("auth", "/api/auth - 认证模块");
        modules.put("system", "/api/system - 系统管理");
        modules.put("product", "/api/product - 商品管理");
        modules.put("inventory", "/api/inventory - 库存管理");
        modules.put("purchase", "/api/purchase - 采购管理");
        modules.put("sales", "/api/sales - 销售管理");
        modules.put("finance", "/api/finance - 财务管理");
        modules.put("report", "/api/report - 报表统计");
        indexInfo.put("modules", modules);
        
        return Result.success(indexInfo);
    }
}